package com.toefl.speaking.activity.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;

import com.toefl.speaking.model.UserInfo;
import com.toefl.speaking.util.MyAsyncTask;

public class BaseActivity extends Activity {

	public Context context;
	protected MyAsyncTask asyncTask;
	protected MyAsyncTask userAsyncTask;
	public static UserInfo userInfo;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		initUI();
		initData();

		asyncTask = new MyAsyncTask(context) {
			@Override
			protected void onPostExecute(Void result) {
				// TODO Auto-generated method stub
				setUI();
				super.onPostExecute(result);

			}

			@Override
			protected Void doInBackground(Void... params) {
				initData();
				return super.doInBackground(params);
			}
		};
		asyncTask.execute();
	}

	protected void setUI() {
		// TODO Auto-generated method stub

	}

	protected void initUI() {
		// TODO Auto-generated method stub

	}

	protected void initData() {
		// TODO Auto-generated method stub

	}

	protected void userOnPost() {
	}

	public void userDoInBackground() {
	}

	/**
	 * 子类View可以通过这个方法获取一个asynctask 只需覆写userDoInBackground，userOnPost，然后执行这个task即可
	 * @return
	 */
	protected MyAsyncTask getUserAsyncTask() {
		userAsyncTask = new MyAsyncTask(context) {
			@Override
			protected void onPostExecute(Void result) {
				userOnPost();
				super.onPostExecute(result);
			}

			@Override
			protected Void doInBackground(Void... params) {
				userDoInBackground();
				return super.doInBackground(params);
			}
		};
		return userAsyncTask;
	}
}
